# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=nspr
pkgver=4.27
pkgrel=0
pkgdesc="Netscape Portable Runtime"
url="https://www.mozilla.org/projects/nspr/"
arch="all"
license="GPL-3.0-only AND LGPL-2.1-only AND LGPL-3.0-only AND MPL-2.0"
options="!check"  # No test suite.
# -dev package does not ship any symlinks so dependency cannot be autodetected
depends_dev="nspr linux-headers"
makedepends="autoconf automake linux-headers"
subpackages="$pkgname-dev"
source="https://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v$pkgver/src/nspr-$pkgver.tar.gz
	fix-getproto.patch
	fix-sgidefs-usage.patch
	"

prepare() {
	mkdir build inst
	default_prepare
}

build() {
	local conf=
	if [ "$CARCH" = "x86_64" ];then
		conf="--enable-64bit"
	fi
	cd "$builddir"/build
	# ./nspr/pr/include/md/_linux.h tests only __GLIBC__ version
	# to detect c-library features, list musl features here for now.
	CFLAGS="$CFLAGS -D_PR_POLL_AVAILABLE -D_PR_HAVE_OFF64_T -D_PR_INET6 -D_PR_HAVE_INET_NTOP -D_PR_HAVE_GETHOSTBYNAME2 -D_PR_HAVE_GETADDRINFO -D_PR_INET6_PROBE" \
	../nspr/configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-debug \
		--enable-optimize \
		--enable-ipv6 \
		$conf
	make CC="${CC:-gcc}" CXX="${CXX:-g++}"
}

package() {
	local file=

	cd "$builddir"/build
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"/usr/lib
	rm -f *.a

	cd "$builddir"/build/config
	install -Dm755 nspr-config "$pkgdir"/usr/bin/nspr-config
	install -Dm644 nspr.pc "$pkgdir"/usr/lib/pkgconfig/nspr.pc
	rm -rf "$pkgdir"/usr/bin/prerr.properties \
		"$pkgdir"/usr/bin/compile-et.pl \
		"$pkgdir"/usr/share/aclocal/nspr.m4 \
		"$pkgdir"/usr/include/nspr/md
}

sha512sums="2be539e6fd5ed8987874147a2bacc3f0b7177cdfddbb1a4f9e5f93575de871584b05fb56ca4e1ba5f7e53074cd4069310658f1559de0f38def208b087b6e6dca  nspr-4.27.tar.gz
7062cc03e38541282226781e67c886c78ca693f7ee96df96509c9429470d294ca6b87ebe05ea809920b9ef78eaa0a0d21ae575a1ac438f148d0c1dc915424613  fix-getproto.patch
69e804907d1a8867912511818d9827e4d7fd36ff44253cb21f4a5527610076874ddf5aada87717ef6454162c21248c9f7c3395376c585129134950c12f90ac0f  fix-sgidefs-usage.patch"
